<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"
	import="java.util.*,com.pub.database.DBFunction"%>
<% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); %>
<% response.setHeader("Cache.Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",0);%>
<jsp:useBean id="webFunction" scope="request"
	class="com.pub.web.WebFunction" />
<!-- 以下為DataView 共用設定 -->
<jsp:useBean id="DataViewForm" scope="request"
	class="com.pub.database.DataViewForm" />
<jsp:setProperty name="DataViewForm" property="pageRowCount" value="10" />
<jsp:setProperty name="DataViewForm" property="nowPageNum" />
<jsp:setProperty name="DataViewForm" property="submitMethod"
	value="POST" />
<jsp:setProperty name="DataViewForm" property="dataViewAction" />
<jsp:setProperty name="DataViewForm" property="filterCol" />
<jsp:setProperty name="DataViewForm" property="filterValue" />
<jsp:setProperty name="DataViewForm" property="dvOrderByFields" />
<jsp:setProperty name="DataViewForm" property="dvOrderBySeq" />
<!-- DataView 設定結束 -->
<!-- Rory Chen 2006/03/09 add Bug Tracking System Version Find Project Code Data Form -->
<% webFunction.setPortal_to_session(request); //set session from portal
   ResourceBundle lrbdWEB_Config = ResourceBundle.getBundle("WEB_Config",Locale.getDefault());
   com.pub.database.DataView DataView=new com.pub.database.DataView(lrbdWEB_Config.getString("DB_ALIAS"),
                            Boolean.valueOf(lrbdWEB_Config.getString("DEBUG")).booleanValue(),
                            lrbdWEB_Config.getString("SOURCE_CHARSET"),
                            lrbdWEB_Config.getString("TARGET_CHARSET"));
   String strSysNO="";

   if(request.getParameter("sys_no")!=null && !request.getParameter("sys_no").trim().equals("")){
     strSysNO=request.getParameter("sys_no").trim().toLowerCase();
   }

if (session.getAttribute("u_id")==null) {
   session.setAttribute("path",String.valueOf(request.getRequestURI()));
   session.setAttribute("param",null);
   response.sendRedirect("/SWD/login.jsp?prg_no=/SWD/pages/pub/find_wkf_table.jsp" + strSysNO);return; } %>

<%
try{
    String strFromSQL="";
    String strWhereSQL="";
    String strdbf_no="";
    String strdbf_name="";

    DataViewForm.setFieldsList("'',wkf_table.dbf_no,wkf_table.dbf_name");
    strFromSQL="wkf_table";
    strWhereSQL=" 1=1 ";

    if(request.getParameter("mydbf_no")!=null && !request.getParameter("mydbf_no").trim().equals("")){
      strdbf_no=request.getParameter("mydbf_no").trim();
      strWhereSQL+=" and wkf_table.dbf_no like '" + DBFunction.getLikeSyntax(DBFunction.getDBType(lrbdWEB_Config.getString("DB_ALIAS"))) + strdbf_no + DBFunction.getLikeSyntax(DBFunction.getDBType(lrbdWEB_Config.getString("DB_ALIAS"))) + "' ";
    }

    if(request.getParameter("mydbf_name")!=null && !request.getParameter("mydbf_name").trim().equals("")){
      strdbf_name=request.getParameter("mydbf_name").trim();
      strWhereSQL+=" and wkf_table.dbf_name like '" + DBFunction.getLikeSyntax(DBFunction.getDBType(lrbdWEB_Config.getString("DB_ALIAS"))) + strdbf_name + DBFunction.getLikeSyntax(DBFunction.getDBType(lrbdWEB_Config.getString("DB_ALIAS"))) +"' ";
    }

    if(strSysNO!=null && !strSysNO.trim().equals("")){
      strFromSQL+=" inner join wkf_sys_table on wkf_sys_table.dbf_no=wkf_table.dbf_no";
      strWhereSQL+=" and wkf_sys_table.sys_no = '" + strSysNO + "' ";
    }

    DataViewForm.setTablesList(strFromSQL);
    DataViewForm.setSQLCondition(strWhereSQL);
    DataViewForm.setOrderByFields("wkf_table.dbf_no");
    DataViewForm.setCountSQL("select count(wkf_table.dbf_no) from " + strFromSQL + " where " + strWhereSQL);
    DataViewForm.setPageActionURI("find_wkf_table.jsp?mydbf_no=" + strdbf_no +
                                                   "&mydbf_name=" + strdbf_name +
                                                   "&sys_no=" + strSysNO);

    boolean blnDebug=false;
    String strColRelation[][]=new String[5][];

    strColRelation[0]=new String[5];
    strColRelation[1]=new String[3];
    strColRelation[2]=new String[3];
    strColRelation[3]=new String[5];
    strColRelation[4]=new String[5];

    strColRelation[0][0]="'SEL'";
    strColRelation[0][1]="INPUT";
    strColRelation[0][2]="WIDTH='5%' align='center' ";
    strColRelation[0][3]="<input type='radio' CLASS='button b_normal' name='sel'  onclick=\"javascript:retVal(%sn%);\" value=";
    strColRelation[0][4]="0";

    strColRelation[1][0]="'檔案編號'";
    strColRelation[1][1]="0";
    strColRelation[1][2]="WIDTH='10%'";

    strColRelation[2][0]="'檔案名稱'";
    strColRelation[2][1]="0";
    strColRelation[2][2]="WIDTH='35%'";

    strColRelation[3][0]="HIDDEN";
    strColRelation[3][1]="INPUT";
    strColRelation[3][2]="WIDTH='0%'";
    strColRelation[3][3]="<input type='hidden' name='dbf_no%sn%' value=";
    strColRelation[3][4]="1";

    strColRelation[4][0]="HIDDEN";
    strColRelation[4][1]="INPUT";
    strColRelation[4][2]="WIDTH='0%'";
    strColRelation[4][3]="<input type='hidden' name='dbf_name%sn%' value=";
    strColRelation[4][4]="2";

    DataViewForm.setColRelation(strColRelation);
    DataViewForm.setPageBtnOnTop(true);
    DataViewForm.setPageBtnOnButtom(false);
    DataViewForm.setFilterShow(false);
    DataViewForm.setJumpPageShow(true);
    DataViewForm.setRowsInfoShow(true);
    DataViewForm.setRowPageShow(false);
    DataViewForm.setExcelShow(false);
    DataViewForm.setOrderEnable(false);
    DataViewForm.setTableDataTrHtml("onmouseover=\"this.className='td_content_ov" +
                                    "er'\" onmouseout=\"this.className='td_content'\"");//設定每筆TR的Html
    DataViewForm.setTableHeaderHtml("class='td_head_grid' align='center'");
%>
<html>

<head>
<script language="javascript" type="">
      // Return values when exit  value: Part No , Description
      function retVal(v_sn){
         window.returnValue=document.all.item('dbf_no' + v_sn).value + ",,,,," +
                            document.all.item('dbf_name' + v_sn).value;
         window.close();
      }
</script>

<title>檔案資料查詢</title>
<LINK HREF="/SWD/workflow.css" REL="stylesheet" TYPE="text/css">
<base target='_self' />
</head>
<body>
<form action="<%=request.getRequestURI() %>" method="POST">
<table>
	<tr>
		<th>系統編號：</th>
		<td><input type="text" name="sys_no" size="30" maxlength="30"
			class="input" value="<%=strSysNO%>" /></td>
	</tr>
	<tr>
		<th>檔案編號：</th>
		<td><input type="text" name="mydbf_no" size="30" maxlength="30"
			class="input" value="<%=strdbf_no%>" /></td>
		<td rowspan="2"><input type="submit" value="尋找" /></td>
	</tr>
	<tr>
		<th>檔案名稱：</th>
		<td><input type="text" name="mydbf_name" size="30" maxlength="30"
			class="input" value="<%=strdbf_name%>" /></td>
	</tr>
</table>
</form>
<%DataView.OutputDataView(DataViewForm, pageContext);%>
</body>
</html>
<%
}catch(Exception e){
  e.printStackTrace();
}finally{
  lrbdWEB_Config=null;
}
%>

